package cn.alcatraz.basic.service.impl;

import cn.alcatraz.basic.mapper.BaseMapper;
import cn.alcatraz.basic.query.BaseQuery;
import cn.alcatraz.basic.service.IBaseService;
import cn.alcatraz.basic.utils.PageList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

// @Service // 不交给spring管理，运行时，实际调用子类。如果交给spring管理，运行时spring不知道该调用父类还是子类
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class BaseServiceImpl<T> implements IBaseService<T> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public List<T> loadAll() {
        return baseMapper.loadAll();
    }

    @Override
    public T loadById(Long id) {
        return baseMapper.loadById(id);
    }

    @Override
    @Transactional
    public void save(T t) {
        baseMapper.save(t);
    }

    @Override
    @Transactional
    public void removeById(Long id) {
        baseMapper.removeById(id);
    }

    @Override
    @Transactional
    public void updateById(T t) {
        baseMapper.updateById(t);
    }

    @Override
    public PageList<T> queryT(BaseQuery baseQuery) {
        return new PageList<>(baseMapper.getCount(baseQuery),baseMapper.queryT(baseQuery));
    }

    @Override
    @Transactional
    public void patchRemove(Long[] ids) {
        baseMapper.patchRemove(ids);
    }
}
